<template>
	<el-table
	    :data="batchTableData"
	    style="width: 100%"
      height=100%
      v-loading="loading"
      element-loading-text="数据正在加载中..."
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
		>

	    <el-table-column
	      label="阶段名称"
        align=center>
	      <template slot-scope="scope">
	        <span style="margin-left: 10px">{{ scope.row.phaseName }}</span>
	      </template>
	    </el-table-column>
		<el-table-column
		  label="检查开始日期"
		  align=center
		 >
		  <template slot-scope="scope">
		    <i class="el-icon-time"></i>
		    <span style="margin-left: 10px">{{ scope.row.phaseDepartmentStart }}</span>
		  </template>
		</el-table-column>
		<el-table-column
		  label="检查结束日期"
		  align=center
		  >
		  <template slot-scope="scope">
		    <i class="el-icon-time"></i>
		    <span style="margin-left: 10px">{{ scope.row.phaseDepartmentEnd }}</span>
		  </template>
		</el-table-column>
		</el-table-column>
	    <el-table-column
        align=center
        label="操作">
	      <template slot-scope="scope">
	        <el-button
	          size="mini"
            type="success"
	          @click="enterBatch(scope.$index, scope.row)" :disabled="scope.row.isLock==1">开始检查</el-button>
	      </template>
	    </el-table-column>
	  </el-table>
</template>

<script>
	export default {
		created() {
      this.teacherInfo=this.$store.state.info
			this.getAllData()
			this.getNowDate()
		},
	  data() {
	      return {
       teacherinfo:'',
			 //batch表数据
	     batchTableData:[],
       MyDepData:[],
			 //yyyy-mm-dd型日期
			 nowDate:'',
			 //加载状态
			 loading:true,
       teacherInfo:''
	      }
	    },
	    methods: {
	     enterBatch(index, row) {
            this.$router.push({path:'/phaseDepAudit',query:{phaseId:row.phaseId}})
                console.log(index, row);
	      },
       getPhaseIsAudit(){
         return this.$api.department.getDepartmentPhaseByDepId({depId:9}).then((res)=>{
          console.log(res)
          for (var i = 0; i < res.data.data.length; i++) {
            for (var j = 0; j < this.MyDepData.length; j++) {
              if(res.data.data[i].batchId==this.MyDepData[j].phaseId && res.data.data[i].depId==this.teacherInfo.bmbh){
                this.$set(this.MyDepData[j],'isLock',res.data.data[i].status)
              }
            }
          }
          this.batchTableData=this.MyDepData.filter((item)=>{
            return  new Date(this.nowDate) >=  Date.parse(item.phaseDepartmentStart)
            && new Date(this.nowDate) <= Date.parse(item.phaseDepartmentEnd) && item.status==5 && item.type==2||
            new Date(this.nowDate) >=  Date.parse(item.phaseDepartmentStart)
            && new Date(this.nowDate) <= Date.parse(item.phaseDepartmentEnd) && item.status==6 && item.type==2
            })
        })
      },
		  //获得数据Axios
		     getAllData(){
			    this.$api.phase.getAllPhase({})
			   .then((res)=>{
          this.MyDepData=res.data.data
          this.getPhaseIsAudit()
          this.loading=false
			  })
		  }
		  ,
		  //得到当前日期
		  getNowDate(){
		    var nowDate = new Date();
		    var year = nowDate.getFullYear();
		    var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;
		    var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
		     .getDate();
		    var dateStr = year + "-" + month + "-" + day;
		    this.nowDate=dateStr
		    console.log("现在日期："+this.nowDate)
		  },
	    }
	  }
</script>

<style scoped>

</style>
